package cn.dglydrpy.fundmanagement.controller;

import cn.dglydrpy.fundmanagement.service.IRiskAssessmentService;
import cn.dglydrpy.fundmanagement.service.dto.RiskAssessmentDto;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/riskAssessments")
public class RiskAssessmentController {

    @Autowired
    private IRiskAssessmentService riskAssessmentService;

    @PostMapping("/addRiskAssessment")
    public void addRiskAssessment(@RequestBody RiskAssessmentDto riskAssessmentDto) {
        riskAssessmentService.saveRiskAssessment(riskAssessmentDto);
    }

    @PostMapping("/updateRiskAssessment")
    public void updateRiskAssessment(@RequestBody RiskAssessmentDto riskAssessmentDto) {
        riskAssessmentService.updateRiskAssessment(riskAssessmentDto);
    }

    @PostMapping("/deleteRiskAssessment/{id}")
    public void deleteRiskAssessment(@PathVariable Long id) {
        riskAssessmentService.deleteRiskAssessment(id);
    }

    @GetMapping("/{id}")
    public RiskAssessmentDto getRiskAssessmentById(@PathVariable Long id) {
        return riskAssessmentService.getRiskAssessmentById(id);
    }

    @GetMapping("/getRiskAssessmentsByConditions")
    public Page<RiskAssessmentDto> getRiskAssessmentsByConditions(
            @RequestParam String fundCode,
            @RequestParam String portfolioId,
            @RequestParam String riskLevel,
            @RequestParam int pageNo,
            @RequestParam int pageSize) {
        return riskAssessmentService.getRiskAssessmentsByConditions(fundCode, portfolioId, riskLevel, pageNo, pageSize);
    }

    @GetMapping("/getAllRiskAssessments")
    public List<RiskAssessmentDto> getAllRiskAssessments() {
        return riskAssessmentService.getAllRiskAssessments();
    }

    @PostMapping("/calculateRiskAssessmentForFund")
    public void calculateRiskAssessmentForFund(@RequestParam String fundCode) {
        riskAssessmentService.calculateRiskAssessmentForFund(fundCode);
    }

    @PostMapping("/calculateRiskAssessmentForPortfolio")
    public void calculateRiskAssessmentForPortfolio(@RequestParam Long portfolioId) {
        riskAssessmentService.calculateRiskAssessmentForPortfolio(portfolioId);
    }
}